package yws.mvcrumen.异常处理;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 异常处理器
 */
public class yichangchuliqi implements HandlerExceptionResolver {
    /**
     * 处理异常的业务逻辑
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception ex) {
        //获取到异常对象
        SysExceptions e=null;
        if(ex instanceof SysExceptions){
            e=(SysExceptions) ex;
        }else {
            e=new SysExceptions("系统正在维护...");
        }
        //创建ModelAndView对象
        ModelAndView mv=new ModelAndView();
        mv.addObject("errorMsg",e.getMessage());
        mv.setViewName("error");
        return mv;
    }
}
